package intis

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"zk3/petpal-service/config"
	"zk3/petpal-service/handler/model"
)

var err error

func Mysql() {

	// 参考 https://github.com/go-sql-driver/mysql#dsn-data-source-name 获取详情
	dsn := "root:root@tcp(127.0.0.1:3306)/xy?charset=utf8mb4&parseTime=True&loc=Local"
	config.DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("数据库连接失败")
	} else {
		fmt.Println("数据库连接成功")
	}
	err = config.DB.AutoMigrate(&model.Beauty{}, &model.Package{}, &model.PetPal{}, &model.Address{}, &model.Order{})
	if err != nil {
		panic("数据表迁移失败")
		return
	} else {
		fmt.Println("数据表迁移成功")
	}
}
